package com.crm.manager.controller;

import com.crm.common.core.domain.AjaxResult;
import com.crm.common.core.domain.R;
import com.crm.manager.domain.Activity;
import com.crm.manager.domain.Contracts;
import com.crm.manager.domain.dto.ActivityDto;
import com.crm.manager.domain.dto.ContractDto;
import com.crm.manager.domain.vo.PageVO;
import com.crm.manager.service.BusinessService;
import com.crm.manager.service.ContractService;
import com.crm.manager.service.IActivityService;
import lombok.RequiredArgsConstructor;

import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.Contract;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/contract")
@RequiredArgsConstructor
@Slf4j
public class ContractsController {

    private final ContractService contractService;
    private final BusinessService businessService;
    private final IActivityService activityService;


    @PutMapping("/changeContract/{id}")
    public R changeContract(@PathVariable Integer id, @RequestBody Map map){
        businessService.changeContract(id, map);
        return R.ok();
    }

    @GetMapping("/list")
    public PageVO page(ContractDto contractDto)
    {
        log.info("分页查询活动信息:{}",contractDto);
        PageVO page = contractService.page(contractDto);
        return page;
    }

    @PostMapping
    public R addContract(@RequestBody ContractDto contract) {
        System.out.println("Received contract data: " + contract);
        int result = contractService.addContract(contract);
        return R.ok();
    }


    @GetMapping("/{id}")
    public R getContractById(@PathVariable String id) {

        // 查询合同信息
        Contracts contract = contractService.getContractById(id);
        // 返回结果
        return R.ok(contract);


    }


    @GetMapping("/detail/{id}")
    public R contractById(@PathVariable Integer id) {
        Contracts contractById = contractService.ContractById(id);
        return R.ok(contractById);
    }


    @PutMapping
    public AjaxResult update(@RequestBody Contracts contracts)
    {
        log.info("修改活动信息:{}",contracts);
        contractService.update(contracts);
        return AjaxResult.success();
    }

}